package cn.forge.mall.module.system.dal.mysql.user;

import cn.forge.mall.framework.common.pojo.PageResult;
import cn.forge.mall.framework.core.mapper.BaseMapperX;
import cn.forge.mall.framework.core.query.LambdaQueryWrapperX;
import cn.forge.mall.module.system.controller.admin.user.vo.UserPageReqVO;
import cn.forge.mall.module.system.dal.dataobject.user.AdminUserDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;

@Mapper
public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {

    /**
     * 分页查询后台管理用户
     * @param reqVO
     * @param deptIds
     * @return
     */
    default PageResult<AdminUserDO> selectPage(UserPageReqVO reqVO, Collection<Long> deptIds) {
        return selectPage(reqVO, new LambdaQueryWrapperX<AdminUserDO>()
                .likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
                .likeIfPresent(AdminUserDO::getUsername, reqVO.getUsername())
                .eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(AdminUserDO::getDeptId, deptIds)
                .orderByDesc(AdminUserDO::getId));
    }
}
